function [y,d,Ind]=neighbors_y_cv(train_x,train_y)

%NEIGHBORS_Y_CV closest neighbor outcome, e.g. for crossvalidation
%Syntax: [y,d,Ind]=neighbors_y_cv(train_x,train_y)
%Description: collects outcomes of all closest neighbors, their indeses and
%             distances. y is the outcome of closest neighbor, d is the
%             distance and Ind is its index.
%
%Jonas Almeida, 17 Feb 2006

n=length(train_x(:,1));
%determine matrix of distances
D=squareform(pdist(train_x));
%replace diagonal identity with maximum distance
D(1:n+1:n^2)=max(D(:));
%find closest neighbor
[d,Ind]=min(D);
%and its outcome
y=train_y(Ind,:);
